package mainHandlerClient

import (
	"github.com/micro/go-micro/v2"
	"github.com/micro/go-plugins/broker/redis/v2"
	"github.com/micro/go-plugins/registry/etcdv3/v2"
	"gomicro/memberMicro/fjmMessage"
	"gomicro/memberMicro/fjmServer/brokerValue"
	"gomicro/memberMicro/fjmServer/handler"
	"log"
	"math/rand"
	"strconv"
)


func init(){
	//创建一个新的服务对象实例
	service := micro.NewService(
		micro.Name("member_micro_service_new"),
		micro.Version("v2.7.0"),
		micro.Registry(etcdv3.NewRegistry()),
		micro.Broker(redis.NewBroker()),

	)

	//服务初始化
	service.Init()

	brokerValue.Pub = service.Server().Options().Broker
	if err := brokerValue.Pub.Connect(); err != nil {
		log.Fatal(" broker connection failed, error : ", err.Error())
	}

	//注册
	hs := handler.MemberHandlerCuda{
		Tag :strconv.Itoa(rand.Int()),
	}
	fjmMessage.RegisterMemberServiceHandler(service.Server(), &hs)  //new(handler.StudentHandlerCuda)

	//运行
	err := service.Run()
	if err != nil {
		log.Fatal(err)
	}
}